package com.example.demo.controller;

import com.example.demo.dto.ResultDto;
import com.example.demo.dto.request.ProductEditReqDto;
import com.example.demo.dto.request.ProductInsertReq;
import com.example.demo.dto.request.ProductQueryReqDto;
import com.example.demo.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author YU JIANG
 * @date 2020/07/024
 */
@RestController
@RequestMapping("/product")
@Slf4j
public class ProductController {

    @Resource
    private ProductService productService;

    @GetMapping
    public ResultDto query(ProductQueryReqDto dto, @PageableDefault(sort = "id")Pageable pageable) {
        return productService.query(dto, pageable);
    }

    @PostMapping
    public ResultDto save(@RequestBody ProductEditReqDto product) {
        return productService.update(product);
    }
    @PostMapping("/insert")
    public ResultDto insert(@RequestBody ProductInsertReq product) {
        return productService.insert(product);
    }
}
